package com.jeepig.system.service.impl;

import com.jeepig.common.utils.StringUtils;
import com.jeepig.system.domain.SysUserDept;
import com.jeepig.system.mapper.SysUserDeptMapper;
import com.jeepig.system.service.ISysUserDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户商户关联服务
 */
@Service
public class SysUserDeptServiceImpl implements ISysUserDeptService {

    @Autowired
    private SysUserDeptMapper userDeptMapper;

    @Override
    public Long[] selectDeptIdsByUserId(Long userId) {
        List<SysUserDept> sysUserDepts = userDeptMapper.selectSysUserDeptByUserId(userId);
        if(StringUtils.isNotEmpty(sysUserDepts)){
            List<Long> list = sysUserDepts.stream().map(SysUserDept::getDeptId).collect(Collectors.toList());
            if(StringUtils.isNotEmpty(list)){
                Long[] deptIds = new Long[list.size()];
                list.toArray(deptIds);
                return deptIds;
            }
        }
        return null;
    }
}
